/*
 * @Author: 颜礼田 2564217790@qq.com
 * @Date: 2024-09-07 11:15:53
 * @LastEditors: 颜礼田 2564217790@qq.com
 * @LastEditTime: 2024-09-10 17:40:45
 * @FilePath: /webServer/src/service/user/user.service.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Provide } from '@midwayjs/core';
import { ServicesImpl } from '../impl';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { User } from '../../model/user/user';
import { Login } from '../../interface';

@Provide()
export class UserService extends ServicesImpl {
  /**
   * 覆盖实体
   */
  @InjectEntityModel(User)
  services: Repository<User>;

  /**
   * 重写关系
   */
  relations: Array<string>;

  constructor() {
    super();
    this.relations = ['role', 'dept'];
  }

  async login(params: Login) {
    return await this.services.findOne({
      where: { mobile: params.username, password: params.password },
      relations: this.relations,
    });
  }
}
